package com.hsy.swu.other.game2048

class RankItem(var rank: String, val info: String, val pbScore: Int) : Comparable<RankItem> {
    companion object {
        fun hideName(name: String, account: String): String {
            val hidedAccount = account.substring(0, account.length - 4) + "****"
            var hidedName = ""
            if (name.length == 2) {
                hidedName = "${name.substring(0, 1)} *"
            } else {
                name.forEachIndexed { index, char ->
                    hidedName += if (index == 0 || index == name.length - 1) char else " * "
                }
            }
            return "$hidedName  -  $hidedAccount"
        }
    }

    override fun compareTo(other: RankItem): Int {
        // 根据pbScore从大到小进行比较
        return other.pbScore - this.pbScore
    }
}